<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>♥♥♥</title>
</head>
<body>
<h1 style="text-align: center;color: red"> ' ♥♥♥ 吃屁</h1>

<script>
/*
    function flattern(data) {
        return data.reduce((iter, val) => {
            if(val.isCheck) iter.push(val.id);
            return val.children ? [...iter, ...flattern(val.children)] : iter;
        }, []);
    }

    var result = flattern(data);
    console.log(result);

}*/


    const data = `[
    {
      "id": "1",
      "label": "能动中心",
      "type": "1",
      "children": [
        {
          "id": "11",
          "label": "罐底视频",
          "type": "2",
          "children": [
            {
              "id": "111",
              "type": "3",
              "label": "四高炉6道"
            },
            {
              "id": "112",
              "type": "3",
              "label": "西渣罐底"
            }
          ]
        },
        {
          "id": "12",
          "label": "煤气柜站",
          "type": "2",
          "children": [
            {
              "id": "121",
              "type": "3",
              "label": "13号道口02"
            },
            {
              "id": "122",
              "type": "3",
              "label": "13号道口01"
            },
            {
              "id": "123",
              "type": "3",
              "label": "能动中心楼顶"
            }
          ]
        },
        {
          "id": "13",
          "label": "能动中心楼顶",
          "type": "2",
          "children": [
            {
              "id": "131",
              "type": "3",
              "label": "44455666"
            }
          ]
        }
      ]
    },
    {
      "id": "2",
      "label": "炼铁厂",
      "type": "1",
      "children": [
        {
          "id": "21",
          "label": "星云智联",
          "type": "2",
          "children": [
            {
              "id": "211",
              "type": "3",
              "label": "程控楼3楼"
            },
            {
              "id": "212",
              "type": "3",
              "label": "程控楼1楼过道西侧"
            },
            {
              "id": "213",
              "type": "3",
              "label": "程控楼2楼大厅"
            },
            {
              "id": "214",
              "type": "3",
              "label": "公司主楼5楼西侧"
            }
          ]
        },
        {
          "id": "22",
          "label": "翻车机溜车线区域",
          "type": "2",
          "children": [
            {
              "id": "221",
              "type": "3",
              "label": "炼钢球罐全貌1"
            }
          ]
        },
        {
          "id": "23",
          "label": "焦化化产作业区",
          "type": "2",
          "children": [
            {
              "id": "231",
              "type": "3",
              "label": "4#万立储槽全貌"
            },
            {
              "id": "232",
              "type": "3",
              "label": "4#万立中压氧压机"
            },
            {
              "id": "233",
              "type": "3",
              "label": "4#万立变电所低压室"
            }
          ]
        }
      ]
    },
    {
      "id": "3",
      "label": "炼钢厂",
      "type": "1",
      "children": [
        {
          "id": "31",
          "label": "熔融金属及吊运区域",
          "type": "2",
          "children": [
            {
              "id": "311",
              "type": "3",
              "label": "8号吊点鞍马座"
            },
            {
              "id": "312",
              "type": "3",
              "label": "8号起吊点右"
            }
          ]
        },
        {
          "id": "32",
          "label": "区域监控",
          "type": "2",
          "children": [
            {
              "id": "321",
              "type": "3",
              "label": "测试点33"
            },
            {
              "id": "322",
              "type": "3",
              "label": "原料跨1"
            },
            {
              "id": "323",
              "type": "3",
              "label": "板坯LH钒铁柜"
            }
          ]
        },
        {
          "id": "33",
          "label": "罐号识别",
          "type": "2",
          "children": [
            {
              "id": "331",
              "type": "3",
              "label": "修罐间东头"
            }
          ]
        }
      ]
    },
    {
      "id": "4",
      "label": "冷轧厂",
      "type": "1",
      "children": [
        {
          "id": "41",
          "label": "轧钢作业区",
          "type": "2",
          "children": [
            {
              "id": "411",
              "type": "3",
              "label": "轧机主控室"
            }
          ]
        },
        {
          "id": "42",
          "label": "普冷作业区",
          "type": "2",
          "children": [
            {
              "id": "421",
              "type": "3",
              "label": "原料库1"
            },
            {
              "id": "422",
              "type": "3",
              "label": "原料库2"
            }
          ]
        },
        {
          "id": "43",
          "label": "镀锌作业区",
          "type": "2",
          "children": [
            {
              "id": "431",
              "type": "3",
              "label": "生产运行检测"
            },
            {
              "id": "432",
              "type": "3",
              "label": "轧机高压室"
            }
          ]
        },
        {
          "id": "44",
          "label": "点检维护作业区",
          "type": "2",
          "children": [
            {
              "id": "441",
              "type": "3",
              "label": "退火炉4"
            },
            {
              "id": "442",
              "type": "3",
              "label": "退火炉1"
            }
          ]
        }
      ]
    }
  ]`


    // 存放最后一层子节点
    const lastChildArr  = []
    /**
     * 获取最后一个子集的两个兄弟元素
     */
    function getLastChildTwoNode(treeData){
        for (const tree of treeData) {
            if(tree.children && tree.children.length && tree.children.children && tree.children.children.length){
                getLastChildTwoNode(tree.children)
            } else {
                // 这时候是最后一层
                lastChildArr.push(tree.children)
            }
        }
        return lastChildArr;
    }
    console.log('getLastChildTwoNode(treeData)', getLastChildTwoNode(JSON.parse(data)))

</script>
</body>
</html>